package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * projectName: com.atguigu.lease.web.admin.custom.converter
 *
 * @author: 吴振鹏
 * description:
 * time: 2025/7/7 19:08
 */
@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {

        for(ItemType itemType : ItemType.values()){
            if(itemType.getCode() == Integer.parseInt(source)){
                return itemType;
            }
        }
        throw new RuntimeException("非法参数异常，不支持！");
    }
}
